package com.cadre.common.utils.oldutil;

import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;

import java.util.*;

/* loaded from: JianliCellHandler.class */
public class JianliCellHandler implements CellHandler {
    @Override // com.tdqy.cadre.modular.profess.common.report.CellHandler
    public void setValue(XWPFParagraph paragraph, Map data) {
        setV(paragraph, data.get(paragraph.getCTP().getBookmarkStartArray(0).getName()).toString());
    }

    private void setV(XWPFParagraph paragraph, String bookValue) {
        XWPFRun run = paragraph.createRun();
        int fontsize = executeFontSize(NStringUtils.splitText(bookValue));
        run.setFontSize(fontsize);
        RenmbReportHelper.setSpacing(paragraph, initFontSpaceMap().get(Integer.valueOf(fontsize)));
        RenmbReportHelper.setCellText(run, bookValue);
    }

    private Map<Integer, String> initFontSpaceMap() {
        Map<Integer, String> map = new LinkedHashMap<>();
        map.put(14, "300");
        map.put(12, "270");
        map.put(11, "260");
        map.put(10, "230");
        map.put(9, "190");
        map.put(8, "180");
        map.put(7, "160");
        map.put(6, "140");
        map.put(5, "120");
        return map;
    }

    private int executeFontSize(String[] text) {
        int[] lengthrules = {60, 70, 76, 85, 95, 107, 122, 143, 150};
        int[] lineRulesNew = {23, 26, 27, 30, 36, 38, 43, 49, 55};
        int[] fontsizes = {14, 12, 11, 10, 9, 8, 7, 6, 5};
        int fontsizeFlength = 6;
        int fontsizeFline = 6;
        List<Integer> lengths = new ArrayList<>();
        for (String str : text) {
            lengths.add(Integer.valueOf(NStringUtils.getWordCount(str)));
        }
        int maxlength = ((Integer) Collections.max(lengths)).intValue();
        int maxline = text.length;
        int i = 0;
        while (true) {
            if (i >= lengthrules.length) {
                break;
            } else if (maxlength <= lengthrules[i]) {
                fontsizeFlength = fontsizes[i];
                System.out.println("根据每行字数设置的字体大小为：" + fontsizeFlength);
                break;
            } else {
                i++;
            }
        }
        int i2 = 0;
        while (true) {
            if (i2 >= lineRulesNew.length) {
                break;
            } else if (maxline <= lineRulesNew[i2]) {
                fontsizeFline = fontsizes[i2];
                System.out.println("根据行数设置的字体大小为：" + fontsizeFline);
                break;
            } else {
                i2++;
            }
        }
        return fontsizeFlength >= fontsizeFline ? fontsizeFline : fontsizeFlength;
    }
}
